/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	AStoreQueryParamConverter.java
 * Created：		2016年9月5日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.notice.converter;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.KV;
import com.thor.commons.entity.UCN;
import com.thor.palmmall.rest.notice.ANoticeParam;
import com.thor.palmmall.spi.notice.SNoticeParam;

/**
 * @author wolv
 *
 */
public class SNoticeParamConverter implements Converter<ANoticeParam, SNoticeParam> {

	public static SNoticeParamConverter getInstance() {
		if (instance == null)
			instance = new SNoticeParamConverter();
		return instance;
	}

	private static SNoticeParamConverter instance;

	private SNoticeParamConverter() {
	}

	@Override
	public SNoticeParam convert(ANoticeParam source) {
		if (source == null)
			return null;

		SNoticeParam target = new SNoticeParam();
		target.setPage(source.getPage());
		target.setPageSize(source.getPageSize());
		target.setUser(UCN.newInstance(source.getUser()));
		target.setUserGroups(new ArrayList<KV>());
		if (source.getUserGroups() != null)
			for (KV sourceUserGroup : source.getUserGroups())
				target.getUserGroups().add(KV.newInstance(sourceUserGroup));
		target.setOrder(source.getOrder());

		return target;
	}

}
